<%--
  Created by IntelliJ IDEA.
  User: mi
  Date: 2019/5/30
  Time: 9:01
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html>
<head>
    <title>职务类型</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/mater.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/vendor.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/css/styles.css">
    <link rel="shortcut icon" href="${pageContext.request.contextPath}/images/favicon.png">
    <script src="${pageContext.request.contextPath}/js/jquery2.js"></script>
    <style type="text/css">/* Chart.js */
    @-webkit-keyframes chartjs-render-animation {
        from {
            opacity: 0.99
        }
        to {
            opacity: 1
        }
    }

    @keyframes chartjs-render-animation {
        from {
            opacity: 0.99
        }
        to {
            opacity: 1
        }
    }

    .chartjs-render-monitor {
        -webkit-animation: chartjs-render-animation 0.001s;
        animation: chartjs-render-animation 0.001s;
    }
    </style>
    <style>
        .remodal-bg.with-red-theme.remodal-is-opening,
        .remodal-bg.with-red-theme.remodal-is-opened {
            filter: none;
        }

        .remodal-overlay.with-red-theme {
            background-color: #f44336;
        }

        .remodal.with-red-theme {
            background: #fff;
        }
    </style>
</head>
<script>
    $(function () {
        $.ajax({
            type: "get",
            url: "${pageContext.request.contextPath}/duc/queryDcuTypeAll",
            dataType: "json",
            success: function (msg) {
                $.each(msg, function (index, data) {
                    var tr =
                        "<tr onclick='fun(this);' data-toggle=\"modal\" data-target=\"#myModal\" >" +
                        "<td >" + data.id + "</td>" +
                        "<td >" + data.zbian + "</td>" +
                        "<td >" + data.zname + "</td>" +
                        "<td >" + data.tname + "</td>" +
                        "<td >" + data.zdj + "</td>" +
                        "</tr>"
                    $("#showTbody").append(tr);
                })
            },
            error: function () {
                alert("失败")
            }
        });
        $.ajax({
            type: "get",
            url: "${pageContext.request.contextPath}/ducType/queryDucTypeAll",
            dataType: "json",
            success: function (msg) {
                $.each(msg, function (index, data) {
                    var options = "<option name='opt' value='" + data.id + "'>" + data.tname + "</option>";
                    $("#ductypeId").append(options);
                })
            },
            error: function () {
                alert("失败")
            }
        });
    })
</script>
<body>
<div class="card-body">
    <table class="table table-striped">
        <thead>
        <tr>
            <th>
                主键
            </th>
            <th>
                职务编号
            </th>
            <th>
                职务名称
            </th>
            <th>
                对应职务类型
            </th>
            <th>
                职务等级
            </th>
        </tr>
        </thead>
        <tbody id="showTbody">

        </tbody>
    </table>

    <script>
        function fun(obj) {
            var firstElement = obj.firstChild;
            $("#zid").val(firstElement.innerText);
            $("#oldId").val(firstElement.innerText);
            $("#zid").prop("disabled", "disabled");
            var innertTextValue1 = firstElement.nextSibling;
            $("#zbian").val(innertTextValue1.innerText);
            var innertTextValue2 = firstElement.nextSibling.nextSibling;
            $("#zname").val(innertTextValue2.innerText);
            var innertTextValue3 = firstElement.nextSibling.nextSibling.nextSibling;
            var opts = $("[name='opt']");
            for (var i = 0; i < opts.length; i++) {
                if (opts[i].innerText == innertTextValue3.innerText) {
                    $(opts[i]).prop("selected", "selected");
                }
            }
            var innertTextValue4 = firstElement.nextSibling.nextSibling.nextSibling.nextSibling;
            $("#zdj").val(innertTextValue4.innerText);
            $("#ductId").val(firstElement.innerText);
        }

        var a = 0;
        $(function () {
            //修改职务
            $("#btnUpdat").click(function () {
                var c = $("#chec");
                if (c[0].checked) {
                    $.ajax({
                        url: "duc/updateDuctById",
                        data: $("#ductFrom").serialize(),
                        dataType: "",
                        success: function (msg) {
                            window.location.reload();
                        },
                        error: function () {
                            window.location.href = "404.jsp";
                        }
                    });
                } else {
                    alert("请勾选")
                }
            });

            //删除职务
            $("#btnDelete").click(function () {
                var c = $("#chec");
                if (c[0].checked) {
                    $.ajax({
                        url: "duc/deleteDuctypeById",
                        data: $("#ductFrom").serialize(),
                        success: function (msg) {
                            if (msg.indexOf("123") != -1) {
                                alert("该职务已被使用不能删除")
                            }
                            window.location.reload();
                        },
                        error: function () {
                            window.location.href = "404.jsp";
                        }
                    });
                } else {
                    alert("请勾选")
                }
            });

            //修改职务id
            $("#btnUpdat_Id").click(function () {
                var c = $("#chec");
                if (c[0].checked) {
                    $.ajax({
                        url: "duc/updateDuctById",
                        data: $("#ductFrom").serialize(),
                        dataType: "",
                        success: function (msg) {
                            window.location.reload();
                        },
                        error: function () {
                            window.location.href = "404.jsp";
                        }
                    });
                } else {
                    alert("请勾选")
                }
            });
        });

        function reverse() {
            if (a % 2 == 0) {
                $("#zid").prop("disabled", false);
                $("#zbian").prop("hidden", "hidden");
                $("#zname").prop("hidden", "hidden");
                $("#zdj").prop("hidden", "hidden");
                $("#ductypeId").prop("hidden", "hidden");
                a++;
            } else {
                $("#zid").prop("disabled", true);
                $("#zbian").prop("hidden", false);
                $("#zname").prop("hidden", false);
                $("#zdj").prop("hidden", false);
                $("#ductypeId").prop("hidden", false);
                a++;
            }
        }
    </script>

    <div class="card-body">
        <form class="form-inline" id="ductFrom">
            <label class="sr-only" for="zid">职务主键</label>
            <input type="text" class="form-control mb-2 mr-sm-2" id="zid" name="id" placeholder="id">
            <label class="sr-only" for="zbian">职务编号</label>
            <input type="text" class="form-control mb-2 mr-sm-2" id="zbian" name="zbian" placeholder="zbian">
            <label class="sr-only" for="zname">职务名称</label>
            <input type="text" class="form-control mb-2 mr-sm-2" id="zname" name="zname" placeholder="zname">
            <label class="sr-only" for="ductypeId">职务类型名称</label>
            <select class="form-control form-control-lg" name="ductypeId" id="ductypeId" style="margin-top: -6px">

            </select>
            <label class="sr-only" for="zdj">职务等级</label>
            <input type="text" class="form-control mb-2 mr-sm-2" id="zdj" name="zdj" placeholder="zdj">
            <input type="text" class="form-control mb-2 mr-sm-2" name="id" hidden id="ductId">
            <div class="form-check mx-sm-2">
                <label class="form-check-label">
                    <input type="checkbox" class="form-check-input" id="chec">
                    确认吗?
                    <i class="input-helper"></i></label>
            </div>
            <input type="text" id="oldId" name="oldId" hidden/>
        </form>
        <button class="btn btn-gradient-primary mb-2" id="btnUpdat">Update</button>
        <button class="btn btn-gradient-primary mb-2" id="btnUpdat_Id">Update-ID</button>
        <button class="btn btn-gradient-primary mb-2" id="btnDelete">delete</button>
        <button class="btn btn-gradient-primary mb-2" onclick="reverse();">reverse</button>
    </div>
    <%--<script>
        $(function () {
            $.ajax({
                type: "get",
                url: "positionController/queryPositionAll",
                dataType:"json",
                success: function (msg) {
                    $.each(msg,function (index,data) {
                        var options="<option value='"+data.id+"'>"+data.wname+"</option>";
                        $("#pid").append(options);
                    });
                },
                error: function () {
                    window.location.href="404.jsp";
                }
            });

            $("#groupBtn").click(function () {
                var dept=$("#groupFrom").serialize();
                $.ajax({
                    type: "post",
                    url: "dept/stratGroupDept",
                    data:dept,
                    dataType:"",
                    success: function (msg) {
                        window.location.href="showDeptData.jsp";
                    },
                    error: function () {
                        window.location.href="404.jsp";
                    }
                })
            });
        });
    </script>--%>
</div>
</body>
</html>
